package com.sdx.console.transaction.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.entity.BaseEntity;
import com.ibeetl.admin.core.entity.CoreUser;
import com.ibeetl.admin.core.file.FileItem;
import com.ibeetl.admin.core.file.FileService;
import com.ibeetl.admin.core.service.CorePlatformService;
import com.ibeetl.admin.core.util.DateUtil;
import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.util.ValidateConfig;
import com.ibeetl.admin.core.web.AuthorizedBaesController;
import com.ibeetl.admin.core.web.JsonResult;
import com.sdx.common.utils.EncryptUtil;
import com.sdx.common.utils.JacksonUtils;
import com.sdx.common.utils.MD5;
import com.sdx.console.transaction.entity.FinTransForRefund;
import com.sdx.console.transaction.entity.FinTransaction;
import com.sdx.console.transaction.entity.FinTransactionRefund;
import com.sdx.console.transaction.entity.RefundExport;
import com.sdx.console.transaction.service.FinTransactionRefundService;
import com.sdx.console.transaction.service.FinTransactionService;
import com.sdx.console.transaction.web.query.FinTransactionRefundQuery;
import com.sdx.payment.RefundResult;
import com.sdx.payment.service.IPaymentService;
import com.sdx.payment.wxpay.WxPayConfig;
import com.sdx.payment.wxpay.WxpayService;
import com.sdx.service.ConfigService;
import org.apache.commons.collections.bag.SynchronizedSortedBag;
import org.apache.commons.lang3.StringUtils;
import org.beetl.sql.core.engine.PageQuery;
import org.dom4j.*;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;

/**
 * 退款 接口
 */
@RequestMapping("/trans/refund")
@Controller
public class FinTransactionRefundController extends AuthorizedBaesController {
	private static final Logger log = LoggerFactory.getLogger("REFOND");
    private static final String MODEL = "/trans/refund";
	private static final String NOTIFY_RESPONSE = "<xml> \n" +
			"  <return_code><![CDATA[SUCCESS]]></return_code>\n" +
			"  <return_msg><![CDATA[OK]]></return_msg>\n" +
			"</xml>";

    @Autowired
    private FinTransactionRefundService refundService;

    @Autowired
    private WxpayService wxpayService;

    @Autowired
    FileService fileService;

    @Autowired
    CorePlatformService platformService;

    @GetMapping("/test.do")
    @ResponseBody
    public String test(String refundId) {
		return refundService.selectMchId(refundId);
    }

    @Autowired
    private FinTransactionService finTransactionService;

    /* 页面 */

    @RequestMapping("/{refundId}/notify.do")
    @ResponseBody
    public String refundNotify(@PathVariable(name="refundId") String refundId,@RequestBody String xml) {
		log.info("refundNotify return xml,"+xml);
	    String xmltemp = xml.toUpperCase();
	    if (xmltemp.contains("<!DOCTYPE") || xmltemp.contains("<!ENTITY")) {
	    	log.error("xxe攻击。"+xml);
	    	return "xxe";
	    }
	    Document doc = null;
	    try {
		    doc = DocumentHelper.parseText(xml);
		    Element root = doc.getRootElement();
			Node node = root.selectSingleNode("return_code");
			FinTransactionRefund refund = new FinTransactionRefund();
			refund.setRefundId(refundId);
			if (!"SUCCESS".equalsIgnoreCase(node.getStringValue())) {
				//退款失败
				node = root.selectSingleNode("return_msg");
				refund.setRefundStatus(-2);
				if (node!=null) {
					refund.setErrorMsg(node.getStringValue());
				}
				refundService.updateTemplate(refund);
			} else {
				//退款成功
				//解密信息
				node = root.selectSingleNode("req_info");
				try {
					String info = node.getStringValue();
					/**
					 * 解密步骤如下：
					 （1）对加密串A做base64解码，得到加密串B
					 （2）对商户key做md5，得到32位小写key* ( key设置路径：微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置 )
					 （3）用key*对加密串B做AES-256-ECB解密（PKCS7Padding）
					 */
					byte[] bytes = Base64.getDecoder().decode(info);
					//获取商户key
					String mchId = refundService.selectMchId(refundId);
					//获取微信商户配置
					WxPayConfig payConfig = wxpayService.getWxPayConfig(mchId);
					String key = payConfig.getKey();
					key = MD5.MD5Encode(key);

					//解密
					info = EncryptUtil.aesDecrypt(bytes,key);

					doc = DocumentHelper.parseText(info);
					root = doc.getRootElement();
					node = root.selectSingleNode("refund_status");
					if (!"SUCCESS".equalsIgnoreCase(node.getStringValue())) {
						refund.setRefundStatus(-2);
						refund.setErrorMsg("退款失败，状态码："+node.getStringValue());
						refundService.updateTemplate(refund);
						return NOTIFY_RESPONSE;
					}
					node = root.selectSingleNode("out_refund_no");
					String revRefundId = node.getStringValue();

					if (!refundId.equalsIgnoreCase(revRefundId)) {
						refund.setRefundStatus(-2);
						refund.setErrorMsg("接口返回id是，"+revRefundId);
						refundService.updateTemplate(refund);
						return NOTIFY_RESPONSE;
					}

					node = root.selectSingleNode("refund_fee");
					long refundFee = Long.parseLong(node.getStringValue());
					refund.setRefundStatus(4);
					refund.setRefundMoney(refundFee);
					refundService.updateTemplate(refund);

					//当所有金额都完成退款后，原订单变更状态为已退款
					refundService.transRefund(refundId);

				}catch(Exception e)
				{
					log.error("refund["+refundId+"]",e);
					log.error("refund["+refundId+"],"+xml);
					refund.setRefundStatus(-2);
					refund.setErrorMsg(e.getMessage());
					refundService.updateTemplate(refund);
				}

			}
	    } catch (DocumentException e) {
		    e.printStackTrace();
		    log.error("refundNotify,"+xml+","+e.getMessage());
		    return e.getMessage();
	    }
	    return NOTIFY_RESPONSE;

    }

    @GetMapping("/index.do")
    @Function("trans.refund.query")
    @ResponseBody
    public ModelAndView index() {
        ModelAndView view = new ModelAndView(MODEL+"/index.html") ;
        return view;
    }

    @GetMapping("/edit.do")
    @Function("trans.refund.edit")
    @ResponseBody
    public ModelAndView edit(String refundId) {
        ModelAndView view = new ModelAndView(MODEL+"/add.html");
        FinTransactionRefund refund = refundService.queryById(refundId);
        view.addObject("refund", refund);
        List<FinTransactionRefund> refundRecord = refundService.findRefundRecord(refund);
        StringBuffer refundRecordStr = new StringBuffer();
        for (FinTransactionRefund finTransactionRefund : refundRecord) {
            refundRecordStr.append(finTransactionRefund.getRefundReason()).append("\r\n");
        }
        view.addObject("refundRecordStr", refundRecordStr.toString());
        List<FinTransaction> tranRecord = refundService.findTranRecord(refund);
        StringBuffer tranRecordStr = new StringBuffer();
        for (FinTransaction finTransaction : tranRecord) {
            tranRecordStr.append(finTransaction.getTradeMemo()).append("\r\n");
        }
        view.addObject("tranRecord", tranRecordStr.toString());
        BaseEntity base = refundService.selectAudit(refundId);
        view.addObject("base", base);
        List<BaseEntity> orderTypeList = refundService.selectOrderType();
        view.addObject("orderTypeList", orderTypeList);
        List<BaseEntity> imgs = refundService.selectImgsById(refundId);
        view.addObject("imgs",imgs);
        try {
			view.addObject("refundJson", JacksonUtils.toJsonString(refund,JacksonUtils.DF1));
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
        return view;
    }

    @GetMapping("/add.do")
    @Function("trans.refund.add")
    @ResponseBody
    public ModelAndView add() {
        ModelAndView view = new ModelAndView(MODEL+"/add.html");
        return view;
    }

    /* ajax json */

    @PostMapping("/list.json")
    @Function("trans.refund.query")
    @ResponseBody
    public JsonResult<PageQuery> list(FinTransactionRefundQuery condtion)
    {
        PageQuery page = condtion.getPageQuery();
        refundService.queryByCondition(page);
        return JsonResult.success(page);
    }

    private JsonResult save(boolean isNew,FinTransactionRefund refund
	) {
    	JsonResult result = JsonResult.success();
		String dir = DateUtil.now("yyyyMMdd");
    	String subPath = "/images/cover/"+dir+"/";

        CoreUser user = platformService.getCurrentUser();
    	if (isNew) {
			refundService.save(refund);
		} else {
            refund.setOperatorId(user.getId().intValue());
            refund.setOperatorName(user.getName());
            refund.setHandleTime(new Date());
			refundService.updateTemplate(refund);
		}
		return result;
	}
    @PostMapping("/add.json")
    @Function("trans.refund.add")
    @ResponseBody
    public JsonResult add(@Validated(ValidateConfig.ADD.class)FinTransactionRefund refund
		)
    {

        return save(true,refund
		);
    }

    @PostMapping("/update.json")
    @Function("trans.refund.edit")
    @ResponseBody
    public JsonResult<String> update(@Validated(ValidateConfig.UPDATE.class)  FinTransactionRefund refund
		) {
		return save(false,refund
		);
    }



    @GetMapping("/view.json")
    @Function("trans.refund.query")
    @ResponseBody
    public JsonResult<FinTransactionRefund>queryInfo(String refundId) {
        FinTransactionRefund refund = refundService.queryById( refundId);
        return  JsonResult.success(refund);
    }

    @PostMapping("/delete.json")
    @Function("trans.refund..del")
    @ResponseBody
    public JsonResult delete(String ids) {
        if (ids.endsWith(",")) {
            ids = StringUtils.substringBeforeLast(ids, ",");
        }
        //List<Long> idList = ConvertUtil.str2longs(ids);
		List<String> idList = new ArrayList<String>();
		Collections.addAll(idList,ids.split(","));
        refundService.batchDelFinTransactionRefund(idList);
        return JsonResult.success();
    }


    @PostMapping("/excel/export.json")
    @Function("trans.refund.export")
    @ResponseBody
    public JsonResult<String> export(HttpServletResponse response,FinTransactionRefundQuery condtion) {
        /**
         * 1)需要用你自己编写一个的excel模板
         * 2)通常excel导出需要关联更多数据，因此refundService.queryByCondition方法经常不符合需求，需要重写一个为模板导出的查询
         * 3)参考ConsoleDictController来实现模板导入导出
         */
        String excelTemplate ="excelTemplates/trans/refund.xls";
//        PageQuery<FinTransactionRefund> page = condtion.getPageQuery();
//        //取出全部符合条件的
//        page.setPageSize(Integer.MAX_VALUE);
//        page.setPageNumber(1);
//        page.setTotalRow(Integer.MAX_VALUE);
        //本次导出需要的数据
        List<RefundExport> list =refundService.queryByConditionExport(condtion);
        Long id = 1L;
        for (RefundExport refundExport : list) {
            if(refundExport.getPayMethod()!=null&&refundExport.getPayMethod()==31){
                refundExport.setMerchantNo(refundExport.getTradeNo());
                refundExport.setTradeNo("");
                refundExport.setTradeMemo(refundExport.getTransactionId());
            }else{
                refundExport.setMerchantNo(refundExport.getTransactionId());
            }
            refundExport.setId(id);
            id ++;
        }
        try(InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) {
            if(is==null) {
                throw new PlatformException("模板资源不存在："+excelTemplate);
            }
            FileItem item = fileService.createFileTemp("退款_"+DateUtil.now("yyyyMMddHHmmss")+".xls");
            OutputStream os = item.openOutpuStream();
            Context context = new Context();
            context.putVar("list", list);
            JxlsHelper.getInstance().processTemplate(is, os, context);
            os.close();
            //下载参考FileSystemContorller
            return  JsonResult.success(item.getPath());
        } catch (IOException e) {
            throw new PlatformException(e.getMessage());
        }

    }

    @PostMapping("/excel/import.do")
    @Function("trans.refund.import")
    @ResponseBody
    public JsonResult importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        if (file.isEmpty()) {
           return JsonResult.fail();
        }
        InputStream ins = file.getInputStream();
        /*解析模板并导入到数据库里,参考DictConsoleContorller，使用jxls reader读取excel数据*/
        ins.close();
        return JsonResult.success();
    }


    /**
     * 审核成功
     * @param refund
     * @return
     */
    @PostMapping("/auditSuccess.json")
    @ResponseBody
    public JsonResult auditSuccess(FinTransactionRefund refund ){

        refund.setRefundStatus(3);
        return save(false,refund);
    }

    /**
     * 驳回
     * @param refund
     * @return
     */
    @PostMapping("/auditFail.json")
    @ResponseBody
    public JsonResult auditFail(FinTransactionRefund refund)
    {
        refund.setRefundStatus(2);
        return save(false,refund);
    }


    /**
     * 退款
     * @param handleMemo
     * @param refundId
     * @param tranId
     * @param refundMoney
     * @return
     */
    @PostMapping("/refund.json")
    @ResponseBody
    public JsonResult refund(String  handleMemo,
                             @RequestParam(required = true)String refundId,
                             @RequestParam(required = true)String tranId,
                             @RequestParam(required = true)int refundMoney)
    {
        JsonResult result;
        FinTransForRefund refund = finTransactionService.selectTransForRefund(tranId);
        FinTransaction transaction = finTransactionService.queryById(tranId);
        String errMsg = null;
        if (refund==null || transaction==null){
            errMsg = "交易单不存在。";
        } else if (refund.getPayFlag().intValue()!=2
                || refund.getRefundMoney().longValue()>=refund.getTotalMoney().longValue()) {
            errMsg = "交易单不是已付款状态，或已经全款退还。";
        }
        if (errMsg!=null) {
            result = JsonResult.failMessage(errMsg);
            return result;
        }
        CoreUser user = platformService.getCurrentUser();

        FinTransactionRefund transactionRefund = new FinTransactionRefund();
        //1、生成退款记录
        transactionRefund.setRefundId(refundId);
        transactionRefund.setOperatorId(user.getId().intValue());
        transactionRefund.setOperatorName(user.getName());
        transactionRefund.setRefundTime(new Date());
        transactionRefund.setRefundStatus(4);
        transactionRefund.setHandleMemo(handleMemo);
        refundService.updateTemplate(transactionRefund);

        //2、调用退款接口
        String msg = "操作成功";
        if(ConfigService.console==null || ConfigService.console!=7){
            IPaymentService paymentService = null;
            if (transaction.getPayMethod()>0 && transaction.getPayMethod()<10) {
                //微信支付
                paymentService = wxpayService;
            } else if (transaction.getPayMethod()>10 && transaction.getPayMethod()<20) {

            } else if (transaction.getPayMethod()>20 && transaction.getPayMethod()<30) {

            }

            if(paymentService!=null){
                RefundResult refundResult = paymentService.refund(refundId,refundMoney,transaction);
                //3、更新退款状态
                FinTransactionRefund updateRefund = new FinTransactionRefund();
                updateRefund.setRefundId(refundId);
                if (refundResult.getResultCode()!=1) {
                    updateRefund.setRefundStatus(-4);
                    updateRefund.setErrorMsg(refundResult.getMessage());
                    refundService.updateTemplate(updateRefund);
                    return JsonResult.failMessage("退款失败，"+refundResult.getMessage());
                } else {
                    updateRefund.setRefundStatus(4);
                    updateRefund.setErrorMsg("接口调用成功。");
                    updateRefund.setRefundMoney(refundResult.getRefundMoney());
                    refundService.updateTemplate(updateRefund);
                }
                msg = "退款成功";
            }else{
                FinTransaction finTransaction  =  new FinTransaction();
                finTransaction.setTransactionId(tranId);
                finTransaction.setPayFlag(4);
                finTransactionService.updateTemplate(finTransaction);
                msg = "非微信支付请手动退款！";
            }
        }
        return JsonResult.successMessage(msg);
    }

    @PostMapping("/qtrefund.json")
    @ResponseBody
    public JsonResult qtrefund(String  handleMemo,
                             @RequestParam(required = true)String refundId,
                             @RequestParam(required = true)String tranId,
                             @RequestParam(required = true)int refundMoney)
    {
        JsonResult result;
        FinTransForRefund refund = finTransactionService.selectTransForRefund(tranId);
        FinTransaction transaction = finTransactionService.queryById(tranId);
        String errMsg = null;
        if (refund==null || transaction==null){
            errMsg = "交易单不存在。";
        } else if (refund.getPayFlag().intValue()!=2
                || refund.getRefundMoney().longValue()>=refund.getTotalMoney().longValue()) {
            errMsg = "交易单不是已付款状态，或已经全款退还。";
        }
        if (errMsg!=null) {
            result = JsonResult.failMessage(errMsg);
            return result;
        }
        CoreUser user = platformService.getCurrentUser();

        FinTransactionRefund transactionRefund = new FinTransactionRefund();
        //1、生成退款记录
        transactionRefund.setRefundId(refundId);
        transactionRefund.setOperatorId(user.getId().intValue());
        transactionRefund.setOperatorName(user.getName());
        transactionRefund.setRefundTime(new Date());
        transactionRefund.setRefundStatus(4);
        transactionRefund.setHandleMemo(handleMemo);
        refundService.updateTemplate(transactionRefund);
        return JsonResult.success();
    }

    @PostMapping("/batchrefund.json")
    @ResponseBody
    public JsonResult batchrefund(String data){
        JSONArray list = JSONArray.parseArray(data);

        //退款失败
        int refundFailCount = 0;
        // 交易单状态不对
        int failCount = 0;
        // 需要手动退款
        int count = 0;
        for (Object object : list) {

            JSONObject refun =(JSONObject) object;

            String  refundId = refun.getString("refundId");
            int refundMoney =  refun.getIntValue("refundApply");
            BaseEntity base = refundService.selectAudit(refundId);
            String  tranId = base.get("tranId").toString();

            FinTransForRefund refund = finTransactionService.selectTransForRefund(tranId);
            FinTransaction transaction = finTransactionService.queryById(tranId);
            String errMsg = null;
            if (refund==null || transaction==null){
                errMsg = "交易单不存在。";
            } else if (refund.getPayFlag().intValue()!=2
                    || refund.getRefundMoney().longValue()>=refund.getTotalMoney().longValue()) {
                errMsg = "交易单不是已付款状态，或已经全款退还。";
            }
            if (errMsg!=null) {
                failCount ++;
                continue;
            }
            CoreUser user = platformService.getCurrentUser();

            FinTransactionRefund transactionRefund = new FinTransactionRefund();
            //1、生成退款记录
            transactionRefund.setRefundId(refundId);
            transactionRefund.setOperatorId(user.getId().intValue());
            transactionRefund.setOperatorName(user.getName());
            transactionRefund.setRefundTime(new Date());
            transactionRefund.setRefundStatus(4);
            transactionRefund.setHandleMemo("");
            refundService.updateTemplate(transactionRefund);

            //2、调用退款接口
            if(ConfigService.console==null || ConfigService.console!=7){
                IPaymentService paymentService = null;
                if (transaction.getPayMethod()>0 && transaction.getPayMethod()<10) {
                    //微信支付
                    paymentService = wxpayService;
                } else if (transaction.getPayMethod()>10 && transaction.getPayMethod()<20) {

                } else if (transaction.getPayMethod()>20 && transaction.getPayMethod()<30) {

                }

                if(paymentService!=null){
                    RefundResult refundResult = paymentService.refund(refundId,refundMoney,transaction);
                    //3、更新退款状态
                    FinTransactionRefund updateRefund = new FinTransactionRefund();
                    updateRefund.setRefundId(refundId);
                    if (refundResult.getResultCode()!=1) {
                        refundFailCount ++;
                        updateRefund.setRefundStatus(-4);
                        updateRefund.setErrorMsg(refundResult.getMessage());
                        refundService.updateTemplate(updateRefund);
                        continue;
                    } else {
                        updateRefund.setRefundStatus(4);
                        updateRefund.setErrorMsg("接口调用成功。");
                        updateRefund.setRefundMoney(refundResult.getRefundMoney());
                        refundService.updateTemplate(updateRefund);
                    }
                }else{
                    count ++;
                    FinTransaction finTransaction  =  new FinTransaction();
                    finTransaction.setTransactionId(tranId);
                    finTransaction.setPayFlag(4);
                    finTransactionService.updateTemplate(finTransaction);
                }
            }


        }
        String msg = "一共："+list.size()+"条数据，交易单有问题："+failCount+"条，退款失败:"+refundFailCount+"条，需要手动退款："+count+"条";

        return JsonResult.successMessage(msg);

    }


    @PostMapping("/batcheolrefund.json")
    @ResponseBody
    public JsonResult batcheolrefund(String ids, HttpServletRequest request) {
        if (ids.endsWith(",")) {
            ids = StringUtils.substringBeforeLast(ids, ",");
        }
        //List<Long> idList = ConvertUtil.str2longs(ids);
        List<String> idList = new ArrayList<String>();
        Collections.addAll(idList,ids.split(","));
        CoreUser user = getLoginUser(request);
        refundService.batchUpdateFinTransactionRefund(idList,user.getName(),user.getId(),new Date());
        refundService.updateFinTrans(idList);
        return JsonResult.success();
    }

    @GetMapping("/eolIndex.do")
    @Function("trans.refund.query")
    @ResponseBody
    public ModelAndView eolIndex() {
        ModelAndView view = new ModelAndView("/trans/eolrefund/index.html") ;
        return view;
    }

    @PostMapping("/excel/eolExport.json")
    @Function("trans.refund.eolexport")
    @ResponseBody
    public JsonResult<String> eolExport(HttpServletResponse response,FinTransactionRefundQuery condtion) {
        /**
         * 1)需要用你自己编写一个的excel模板
         * 2)通常excel导出需要关联更多数据，因此refundService.queryByCondition方法经常不符合需求，需要重写一个为模板导出的查询
         * 3)参考ConsoleDictController来实现模板导入导出
         */
        String excelTemplate ="excelTemplates/trans/eolrefund.xls";
//        PageQuery<FinTransactionRefund> page = condtion.getPageQuery();
//        //取出全部符合条件的
//        page.setPageSize(Integer.MAX_VALUE);
//        page.setPageNumber(1);
//        page.setTotalRow(Integer.MAX_VALUE);
        //本次导出需要的数据
        List<RefundExport> list =refundService.queryByConditionExport(condtion);
        Long id = 1L;
        for (RefundExport refundExport : list) {
            if(refundExport.getPayMethod()!=null&&refundExport.getPayMethod()==31){
                refundExport.setMerchantNo(refundExport.getTradeNo());
                refundExport.setTradeNo("");
                refundExport.setTradeMemo(refundExport.getTransactionId());
            }else{
                refundExport.setMerchantNo(refundExport.getTransactionId());
            }
            if(refundExport.getPayMethod()!=null){
                Integer payMethod = refundExport.getPayMethod();
                if(payMethod<10){
                    refundExport.setPayMethodName("微信支付");
                }else if(payMethod<20){
                    refundExport.setPayMethodName("支付宝支付");
                }
            }
            refundExport.setId(id);
            id ++;
        }
        try(InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(excelTemplate)) {
            if(is==null) {
                throw new PlatformException("模板资源不存在："+excelTemplate);
            }
            FileItem item = fileService.createFileTemp("退款_"+DateUtil.now("yyyyMMddHHmmss")+".xls");
            OutputStream os = item.openOutpuStream();
            Context context = new Context();
            context.putVar("list", list);
            JxlsHelper.getInstance().processTemplate(is, os, context);
            os.close();
            //下载参考FileSystemContorller
            return  JsonResult.success(item.getPath());
        } catch (IOException e) {
            throw new PlatformException(e.getMessage());
        }

    }


}
